package com.cdcas;

import java.util.*;

public class Iterator1Test {
    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        list.add("111");
        list.add("222");
        list.add("333");
        //单向迭代器
//        Iterator<String> iterator = list.iterator();
//        while (iterator.hasNext()) {
//            System.out.println(iterator.next());
//        }
        System.out.println("由前向后输出");
        ListIterator<String> iter = list.listIterator();
        while (iter.hasNext()) {
            System.out.println(iter.next());
        }
        System.out.println("由后向前输出");
        while (iter.hasPrevious()) {
            System.out.println(iter.previous());
        }

        Vector<String> vector = new Vector<>();
        vector.add("www");
        vector.add("baidu");
        Enumeration<String> enu = vector.elements();
        while (enu.hasMoreElements()) {
            System.out.println(enu.nextElement());
        }


    }
}
